/**
 * 表单自定义控制器
 */
app.controller('formSelfCtrl', ['$scope', '$http', function FormSelfController($scope, $http){
	
	/*
	 * 数字框变动
	 */
	$scope.subGrid.numberChange = function(row, field) {
		console.log('row---', row);
		console.log('field---', field);
		row.totalPrice = row.singlePrice * row.num;
	}
}]);

/**
 * 子列表控制器
 */
app.controller('subGridCtrl', ['$scope', '$http', function SubGridController($scope, $http){
	$scope.checkbox.afterSelectDatas = function(rowsSelected) {
		console.log('formSelfCtrl2---', rowsSelected);
    	var rows = [];
    	for (var i = 0; i < rowsSelected.length; i++) {
			var rowSelected = rowsSelected[i];

			var isAdd = true; // 根据现有存在，是否加新行
			for (var j = 0; j < $scope.subGrid.sonlist.length; j++) {
				if ($scope.subGrid.sonlist[j].productCode == rowSelected.code) {
					isAdd = false;
				}
			}

			var type = $scope.valueMap['type'];

			if (isAdd == true) {
				var row = {
					productCode: rowSelected.code,
					productName: rowSelected.name,
					singlePrice: rowSelected.priceIn,
					vgsbmFrom: type == 1 ? 'GS0641' : 'GS0877',
					vgsjcFrom: type == 1 ? '逸思精品' : '逸思库存'
				};
				$scope.subGrid.sonlist.push(row);
			}
		}
	}
}]);